package mobile.pubcrawler;

import java.util.ArrayList;
import mobile.pubcrawler.model.DataModelRating;
import android.content.Context;
import android.text.Html;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

public class RatingsListAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<DataModelRating> ratings = new ArrayList<DataModelRating>();
	
	public RatingsListAdapter(Context context, ArrayList<DataModelRating> ratings){
		this.context = context;
		this.ratings = ratings;
	}
		
	public int getCount(){
		return ratings.size();
	}
	
    public Object getItem(int position) {
        return position;
    }
    
    public long getItemId(int position) {
        return position;
    }
	
    public View getView(int position, View convertView, ViewGroup parent) {
    	
    	DataModelRating currentRating = ratings.get(position);
    	final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    	View view = inflater.inflate(R.layout.ratingslistitem, null);         	
        
    	RatingBar rating = (RatingBar)view.findViewById(R.id.details_ratingbar_review);
    	rating.setRating(currentRating.getStars());
    	
    	TextView reviewer = (TextView)view.findViewById(R.id.details_Reviewer);
        reviewer.setText(Html.fromHtml("<b>"+currentRating.getUser()+"</b>"));
    	
    	TextView date = (TextView)view.findViewById(R.id.details_Date);
    	date.setText(DateFormat.getMediumDateFormat(context).format(currentRating.getDate()));
    	
    	TextView reviewText =  (TextView)view.findViewById(R.id.details_ReviewText);
    	reviewText.setText(currentRating.getComment());
    	reviewText.setTextSize(13);
    	
    	return view;
    }
   
}